﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Applib;

namespace Yule8xWxPromotion.XAgent
{
    public partial class Dailituiguang2 : System.Web.UI.Page
    {
        protected string realname, face, qrcode, ip, address,fxtitle,fxcontent,fxicon;
        protected long count = 30000;
        protected string appid, appsecret, timestamp, noncestr, signature;
        // 务必用https访问
        protected void Page_Load(object sender, EventArgs e)
        {
            List<string[]> listAgent = new List<string[]>();
            listAgent.Add(new string[] { "丘先生", "qiu.png", "qiuqrcode.png" });
            listAgent.Add(new string[] { "亭亭玉立", "ttyl.png", "ttqrcode.png" });
            Random rnd = new Random();
            int i = rnd.Next(listAgent.Count);
            string[] item = listAgent[i];
            realname = item[0];
            face = item[1];
            qrcode = item[2];
            List<string[]> listFx = new List<string[]>();
            listFx.Add(new string[] { "全国有那么多人靠这个赚钱，竟然今天才被曝光", "90后逆袭，仅靠300元，努力不到一个月，轻松月入万元" });
            listFx.Add(new string[] { "快来帮我赚红包！红包天天送！简单易得！", "没有门槛，无论什么人，何时，何地，只要咨询既有红包，简单易得！" });
            //listFx.Add(new string[] { "年轻宝妈在家轻松带娃也能月入万元", "一部手机，一个微信，即时在家辛苦带娃，也能轻松解决家庭经济来源" });
            i = rnd.Next(listFx.Count);
            item = listFx[i];
            fxtitle = item[0];
            fxcontent = item[1];
            //string[] listIcons = new string[] { "share1.png","share2.png","share3.png"};
            //i = rnd.Next(listIcons.Length);
            //fxicon = listIcons[i];
            fxicon = "share3.png";
            ip = IPUtil.HttpIP;
            string html = HttpUtil.HttpGet("http://m.ip138.com/ip.asp?ip=" + ip);
            parseAddress(html);
            // 统计
            count += rnd.Next(100, 2000);
            // 微信分享
            getWxConf();

        }
        void getWxConf()
        {
            appid = AppInfo.AppID;
            appsecret = AppInfo.AppSecret;
            timestamp = WechatUtil.GetTimestamp().ToString();
            noncestr = WechatUtil.GetNonceStr();
            signature = WechatUtil.GetSignature(WechatUtil.GetJSAPITicket(), noncestr, timestamp, Request.Url.ToString());
        }
        void parseAddress(string html)
        {
            int pos = html.IndexOf("本站主数据");
            if (pos > 0)
            {
                // 北京市北京市 百度蜘蛛 联通  47.153.191.255
                // 北京市海淀区 北京歌华有线电视 58.30.21.255
                // 美国
                html = html.Substring(pos + 6);
                html = html.Substring(0, html.IndexOf("<") - 1);
                pos = html.IndexOf("市");
                if (pos < 0)
                {
                    address = "全国";
                }
                else
                {
                    html = html.Substring(0, pos + 1);
                    if (html.IndexOf("省") > -1)
                    {
                        html = html.Substring(html.IndexOf("省") + 1);
                    }
                    else
                    {
                        html = html.Length > 3 ? html.Substring(html.Length - 3) : html;
                    }
                    address = html;
                }
            }
            else
            {
                address = ip;
            }
        }
    }
}